﻿package mortal.game.view.monthInvestment.view
{
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class MonthInvestGetPanel extends GSprite
    {
        private var _investList:GTileList;
        private var _type:int;
        private var _investBtn:GLoadingButton;
        private var _rewardIcon:GImageBitmap;

        public function MonthInvestGetPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MonthInvestGetTitle, 28, -125, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.MonthInvestBg, 28, 10, this));
            this._rewardIcon = UIFactory.gImageBitmap("", 583, -111, this);
            this._investList = UIFactory.tileList(35, 17, 670, 385, this);
            this._investList.rowHeight = 193;
            this._investList.columnWidth = 161;
            this._investList.horizontalGap = 3;
            this._investList.verticalGap = 4;
            this._investList.setStyle("cellRenderer", MonthInvestGetCellRender);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._investList.dispose(param1);
            this._investList = null;
            this._rewardIcon.dispose(param1);
            this._rewardIcon = null;
            if (this._investBtn)
            {
                this._investBtn.dispose(param1);
                this._investBtn = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.InvestmentMonth, this._type));
            return;
        }// end function

        private function getDateProvider() : DataProvider
        {
            var _loc_5:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = MonthInvestmentConfig.instance.rewardArr[this._type];
            var _loc_3:* = _loc_2.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = {type:this._type, index:_loc_4};
                _loc_1.addItem(_loc_5);
                _loc_4++;
            }
            return _loc_1;
        }// end function

        public function updateInvestGetState(param1:int, param2:Boolean = false) : void
        {
            this._type = param1;
            this._investList.dataProvider = this.getDateProvider();
            if (param2)
            {
                if (InvestUtil.isHasInvestmented(this._type))
                {
                    this._investList.scrollToIndex((InvestUtil.getFirstCanGetInvestByType(this._type) - 1));
                }
                else
                {
                    this._investList.scrollToIndex(0);
                }
            }
            this._rewardIcon.imgUrl = "monthInvestTypeIcon_" + this._type + ".png";
            var _loc_3:* = Cache.instance.investment.getTodayInfoByType(this._type);
            if (_loc_3 == null)
            {
                if (this._investBtn == null)
                {
                    this._investBtn = UIFactory.gLoadingButton(ResFileConst.MonthInvestBtn, 556, -35, 115, 42, this);
                    this._investBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
                    this._investBtn.drawNow();
                }
            }
            else if (this._investBtn)
            {
                this._investBtn.dispose();
                this._investBtn = null;
            }
            return;
        }// end function

    }
}
